package com.acoreful.acf2java.commons.beans.model;

import java.util.Map;

@SuppressWarnings("serial")
public final class Response<T> extends BaseModel {

	private int code = 200;
	private String message = "request success";
	private long timestamp = System.currentTimeMillis();
	private Map<String, String> error;
	private Object exception;
	private T result;

	private Response() {
	}

	private Response(int code, String message, T result) {
		this.code = code;
		this.message = message;
		this.result = result;
	}

	private Response(int code, String message, Map<String, String> error, Object exception, T result) {
		super();
		this.code = code;
		this.message = message;
		this.error = error;
		this.exception = exception;
		this.result = result;
	}

	public static <T> Response<T> response(int code, String message, T result) {
		return new Response<T>(code, message, result);
	}

	public static <T> Response<T> response(int code, String message,Map<String, String> error,T result) {
        return new Response<T>(code, message,error,null, result);
    }

	public static <T> Response<T> success() {
		return response(200, "", null);
	}

	public static <T> Response<T> success(T result) {
		return response(200, "", result);
	}

	public static <T> Response<T> success(String message) {
		return response(200, message, null);
	}

	public static <T> Response<T> success(String message, T result) {
		return response(200, message, result);
	}

	public static <T> Response<T> loginRequired() {
		return response(-2, "请登录", null);
	}

	public static <T> Response<T> caughtException() {
		return response(-100, "服务端异常", null);
	}

	public static <T> Response<T> caughtException(String message) {
		return response(-100, message, null);
	}

	public static <T> Response<T> caughtException(String message, Map<String, String> error) {
		return response(-400, message, error, null);
	}

	public int getCode() {
		return code;
	}

	public T getResult() {
		return result;
	}

	public String getMessage() {
		return message;
	}

	public long getTimestamp() {
		return timestamp;
	}

	public Map<String, String> getError() {
		return error;
	}

	public Object getException() {
		return exception;
	}

}